package com.serkol.driving.learning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.bean.MyPage;
import com.serkol.constant.AuthConstant;
import com.serkol.driving.learning.entity.Category;
import com.serkol.driving.learning.mapper.CategoryMapper;
import com.serkol.driving.learning.service.CategoryService;
import com.serkol.driving.learning.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author pingan
* @description 针对表【category】的数据库操作Service实现
* @createDate 2022-06-07 00:16:41
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{
    @Override
    public MyPage findByList(int pageSize, int current) {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("ID");
        Page<Category> page = new Page<>(current, pageSize);
        IPage<Category> loginLogPage = this.baseMapper.selectPage(page, queryWrapper);
        return MyPage.parsePage(loginLogPage);
    }

    @Override
    public List<Map<String,Object>> findByListMini() {
        System.out.println("Lang"+ AuthConstant.getLanguage());
        MyLambdaQueryWrapper<Category> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.langName(Category::getName,Category::getNameUg).as("name").
                select(Category::getId).as("id").
                select(Category::getIcon).as("icon").
                select(Category::getLanguageId).as("languageId").select(Category::getSort).
                select(Category::getContent).as("content")
                .select(Category::getType).as("type")
                .select(Category::getEnable).as("enable");
        queryWrapper.orderByDesc(Category::getId);
        return this.listMaps(queryWrapper);
    }
}




